package com.ysd.qxgl.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import com.ysd.qxgl.dto.RolesDTO;
import com.ysd.qxgl.model.Roles;
import com.ysd.qxgl.service.IRolesService;

import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import io.swagger.annotations.ApiOperation;

@RestController
@RequestMapping("/roles")
public class RolesController {

    @Resource
    private IRolesService rolesService;

    @ApiOperation(value = "查询所有角色",notes = "查询所有角色")
    @GetMapping
    public Map<String ,Object> findAllRoles(){
        List<Roles> list=rolesService.findAllRoles();
        Map<String ,Object> map=new HashMap<>();
        map.put("code", 0);
        map.put("msg", "查询成功");
        map.put("data", list);
        return map;
    }
    @ApiOperation(value = "分页查询角色",notes = "分页查询角色")
    @GetMapping("/findAllRoelsByPage")
    public Map<String ,Object> findAllRolesByPage(@RequestBody RolesDTO dto){
        List<Roles> list=rolesService.findRolesByPage(dto);
        Map<String ,Object> map=new HashMap<>();
        map.put("code", 0);
        map.put("msg", "查询成功");
        map.put("count", rolesService.getCount(dto));
        map.put("data", list);
        return map;
    }
    @ApiOperation(value = "新增一个角色",notes = "新增一个角色" )
    @PostMapping("/addRole")
    public int addRole(@RequestBody Roles roles){
        return rolesService.addRole(roles);
    }
    @ApiOperation(value = "编辑角色信息",notes = "编辑角色信息")
    @PutMapping("/editRole")
    public int editRole(@RequestBody Roles roles){
        return rolesService.editRole(roles);
    }
    @ApiOperation(value = "根据编号删除角色",notes = "根据编号删除绝色")
    @DeleteMapping("/delRoleById/{id}")
    public int delRoleById(@PathVariable String id){
        return rolesService.delRole(id);
    }
}